const app = getApp()
Page({
  data: {
    id: 0,
    item: [],
  },
  /**
   * 载入
   */
  onLoad: function (options) {
    app.getParam(options, (rel) => {
      this.setData({
        id: rel.id,
      })
      this.getCoupon(rel.id);
    });
  },
  //获取优惠券
  getCoupon: function (id) {
    var param = {
      signkey: app.util().getRandom(12),
      id: id,
    }
    app.api().Get('api/v4/allwin/couponuser/getCoupon', param, (result) => {
      if (result.code == 200) {
        this.setData({
          item: result.data,
        });
      }
    })
  },
  //获取首页接口
  getStore: function (store_id) {
    app.api().Get('api/v4/allwin/store/getView', { 'store_id': store_id }, (result) => {
      wx.setNavigationBarTitle({
        title: result.data.name
      })
      this.setData({
        store: result.data
      });
    })
    this.getShop();
    this.getCoupon();
  },
  //分享按钮
  onShareAppMessage: function () {
    var coupon = this.data.item;
    return {
      title: '我领取了【' + coupon.tips + '】的优惠券,快来抢!',
      imageUrl: coupon.img,
      path: '/pages/store/views?ucode=' + app.globalData.loginuser.ucode + '&store_id=' + coupon.store_id
    }
  }
});